package com.numberone.master.common.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class BASE64 {

    /**
     * 编码
     * @param s
     * @return
     */
    public static String encodeBASE64(byte [] bytes) {
        if (null==bytes || 0==bytes.length){
            return null;
        }
        return (new BASE64Encoder()).encode(bytes);
    }

    
    /**
     * 解码
     * @param s
     * @return
     */
    // 将 BASE64 编码的字符串 s 进行解码
    public static byte [] decodeBASE64(String s) {
        if (s == null)
            return null;
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            byte[] b = decoder.decodeBuffer(s);
            return b;
        }
        catch (Exception e) {
            return null;
        }
    }

}
